/*
public class test {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8};
        System.out.println(binarySearch(arr,6));
    }
    public static int binarySearch(int[] arr, int toFind) {
        public static void main(String[] args) {
            int[] arr = {1, 2, 3, 4, 5, 6};
            System.out.println(binarySearch(arr, 6));
        }
        int left = 0;
        int right = arr.length - 1;
        while (left <= right) {

            int mid = (left + right) / 2;
            if (toFind < arr[mid]) {
// 去左侧区间找
                right = mid - 1;
            } else if (toFind > arr[mid]) {
// 去右侧区间找
                left = mid + 1;
            } else {
// 相等, 说明找到了
                return mid;
            }
        }
// 循环结束, 说明没找到
        return -1;
    }






    public static void main(String[] args) {
        int[] arr = {9, 5, 2, 7};
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void bubbleSort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 1; j < arr.length - i; j++) {
                if (arr[j - 1] > arr[j]) {
                    int tmp = arr[j - 1];
                    arr[j - 1] = arr[j];
                    arr[j] = tmp;

                }
            }
        }
    }





    public static boolean induge(int[]arr) {
        for(int i=0;i<arr.length-1;i++) {//之所以是arr.length是为了避免越界
            if (arr[i] > arr[i + 1]) {
                return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        int []arr = {1,2,3,41,5,6};
        System.out.println(induge(arr));
    }
    public int singleNumber(int[] nums) {
        if (nums.length == 1) return nums[0];
        Arrays.sort(nums);
        //第一个和最后一个单独考虑
        if (nums[0] != nums[1]) return nums[0];
        if (nums[nums.length - 1] != nums[nums.length - 2]) return nums[nums.length - 1];
        for(int i = 0; i < nums.length - 1; i++){
            if(nums[i] != nums[i + 1] && nums[i] != nums[i - 1])
                return nums[i];
        }
}*/
